package com.jack.helloworld.adapter;

import androidx.viewpager.widget.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;

import java.util.List;

/**
 * Created by Administrator on 2017/3/8.
 */
public class ViewPageAdapter extends PagerAdapter {

    List<View> listView;
    List<String> listPageViewTitle;

    public ViewPageAdapter(List<View> listView) {
        this.listView = listView;
    }

    public ViewPageAdapter(List<View> listView, List<String> listPageViewTitle) {
        this.listView = listView;
        this.listPageViewTitle = listPageViewTitle;
    }

    @Override
    public int getCount() {
        return listView.size();
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        container.addView(listView.get(position));
        return listView.get(position);
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView(listView.get(position));
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return listPageViewTitle.get(position);
    }
}
